package mk.company.fin.frame.internal;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyVetoException;
import java.util.List;
import java.util.Vector;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.table.DefaultTableModel;

import mk.company.fin.AppConstants;
import mk.company.fin.model.Komintent;
import mk.company.fin.service.MessageService;
import mk.company.fin.service.ModelService;

import org.springframework.context.ApplicationContext;

public class KomintentFrame extends AbstractInternalFrame {

	private static final long serialVersionUID = 1428384147629005389L;
	
	/* SERVICES */
	
	private MessageService messageService;
	private ModelService modelService;
	
	@Override
	public void initialize(ApplicationContext context) {
		setContext(context);
		injectServices();
		// Defaults
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(new Dimension(AppConstants.MainFrame.WIDTH, AppConstants.MainFrame.HEIGHT));
		
		// components
		initComponents();
	}
	
	//component which this frame will be drawn
	JComponent component;
	public KomintentFrame(JComponent component) {
		this.component=component;
		
	}
	/**
	 * Inject services.
	 */
	private void injectServices() {
		messageService = getContext().getBean(MessageService.class);
		modelService=getContext().getBean(ModelService.class);
	}
	@Override
	public void draw() {
		injectServices();
		initComponents();
	}
	
	//Components of ComintentPanel
	private javax.swing.JPanel comintentPanel;
    private javax.swing.JTextField EMBField;
    private javax.swing.JLabel EMBLabel;
    private javax.swing.JTextField accountBankNameField;
    private javax.swing.JLabel accountBankNameLabel;
    private javax.swing.JTextField accountBankNumberField;
    private javax.swing.JLabel accountBankNumberName;
    private javax.swing.JTextField addressField;
    private javax.swing.JLabel addressLabel;
    private javax.swing.JTextField codeField;
    private javax.swing.JLabel codeLabel;
    private javax.swing.JTextField comintentNameField;
    private javax.swing.JLabel comintentNameLabel;
    private javax.swing.JLabel comintentShorNameLabel;
    private javax.swing.JTextField comintentShortNameField;
    private javax.swing.JTextField faxField;
    private javax.swing.JLabel faxLabel;
    private javax.swing.JTextField placeField;
    private javax.swing.JLabel placeLabel;
    private javax.swing.JLabel requiredLabel;
    private javax.swing.JLabel requiredLabel1;
    private javax.swing.JLabel requiredLabel2;
    private javax.swing.JLabel requiredLabel3;
    private javax.swing.JLabel requiredLabel4;
    private javax.swing.JLabel requiredLabel5;
    private javax.swing.JTextField telephoneField;
    private javax.swing.JLabel telephoneLabel;
    private javax.swing.JTextField uniqueTaxNumberField;
    private javax.swing.JLabel uniqueTaxNumberLabel;
    private javax.swing.JButton comintentActionButton;
    
    //components of the ComintentTablePanel
    private javax.swing.JTable comintentTable;
    private javax.swing.JPanel comintentTablePanel;
    private javax.swing.JScrollPane comintentTableScrollPane;
    private DefaultTableModel comintentTableModel;
    private Komintent selectedComintent;

    private List<Komintent> comintentList;
		    
	@SuppressWarnings("all")
	public void initComponents(){
		// title
		setTitle(messageService.getMessage("comintents"));
		//Size
		this.setSize(AppConstants.MainFrame.WIDTH, AppConstants.MainFrame.HEIGHT);
		//Maximize
		try {
			this.setMaximum(true);
		} catch (PropertyVetoException e) {}
		catch (NullPointerException n){}
		//Layout
		this.setLayout(null);
		
		initComintentPanel();
		//ComintentTablePanel
        initComintentTablePanel();
        
        comintentPanel.setVisible(false);
        
        initActionPanel();
		//Setting the layout
        setLayout();
        
        
//        ListSelectionModel rowSelectionModel=comintentTable.getSelectionModel();
//        rowSelectionModel.addListSelectionListener(new ListSelectionListener() {
//			
//			@Override
//			public void valueChanged(ListSelectionEvent e) {
//				int selectedRowIndex=comintentTable.getSelectedRow();
//				if (selectedRowIndex>=0){
//					selectedComintent=comintentList.get(selectedRowIndex);
//					fillSelectedComintentData();
//				}
//			}
//		});
        
      refreshTableData();

      
      //Draw the main InternalFrame
      this.setVisible(true);
      component.add(this);
	}
	
	
	private void initComintentPanel(){
		//Drawing the comintentPanel
		comintentPanel = new javax.swing.JPanel();
		comintentPanel.setBorder(BorderFactory.createTitledBorder(messageService.getMessage("comintent.adding")));
		comintentNameLabel = new javax.swing.JLabel(messageService.getMessage("comintent.name")+":");
		comintentShorNameLabel = new javax.swing.JLabel(messageService.getMessage("comintent.short.name")+":");
		comintentShorNameLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
		comintentNameField = new javax.swing.JTextField();
		comintentNameField.setColumns(20);
		comintentShortNameField = new javax.swing.JTextField();
		comintentShortNameField.setColumns(10);
		uniqueTaxNumberLabel = new javax.swing.JLabel(messageService.getMessage("comintent.unique.tax.number")+":");
		uniqueTaxNumberField = new javax.swing.JTextField();
		uniqueTaxNumberField.setColumns(13);
		placeLabel = new javax.swing.JLabel(messageService.getMessage("comintent.place")+":");
		placeLabel.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
		placeField = new javax.swing.JTextField();
		placeField.setColumns(10);
		addressLabel = new javax.swing.JLabel(messageService.getMessage("comintent.address")+":");
		codeLabel = new javax.swing.JLabel(messageService.getMessage("comintent.code")+":");
		addressField = new javax.swing.JTextField();
		addressField.setColumns(20);
		codeField = new javax.swing.JTextField();
		codeField.setColumns(10);
		telephoneLabel = new javax.swing.JLabel(messageService.getMessage("comintent.telephone")+":");
		faxLabel = new javax.swing.JLabel(messageService.getMessage("comintent.fax")+":");
		telephoneField = new javax.swing.JTextField();
		telephoneField.setColumns(10);
		faxField = new javax.swing.JTextField();
		faxField.setColumns(10);
		EMBLabel = new javax.swing.JLabel(messageService.getMessage("comintent.emb")+":");
		EMBField = new javax.swing.JTextField();
		EMBField.setColumns(13);
		accountBankNameLabel = new javax.swing.JLabel(messageService.getMessage("comintent.bank.account.name")+":");
		accountBankNameField = new javax.swing.JTextField();
		accountBankNameField.setColumns(15);
		accountBankNumberName = new javax.swing.JLabel(messageService.getMessage("comintent.bank.number")+":");
		accountBankNumberField = new javax.swing.JTextField();
		accountBankNumberField.setColumns(15);
		requiredLabel = new javax.swing.JLabel();
		requiredLabel1 = new javax.swing.JLabel();
		requiredLabel2 = new javax.swing.JLabel();
		requiredLabel3 = new javax.swing.JLabel();
		requiredLabel4 = new javax.swing.JLabel();
		requiredLabel5 = new javax.swing.JLabel();
		requiredLabel.setForeground(new java.awt.Color(255, 0, 0));
        requiredLabel.setText("*");
        requiredLabel1.setForeground(new java.awt.Color(255, 0, 0));
        requiredLabel1.setText("*");
        requiredLabel2.setForeground(new java.awt.Color(255, 0, 0));
        requiredLabel2.setText("*");
        requiredLabel3.setForeground(new java.awt.Color(255, 0, 0));
        requiredLabel3.setText("*");
        requiredLabel4.setForeground(new java.awt.Color(255, 0, 0));
        requiredLabel4.setText("*");
        requiredLabel4.setVisible(false);
        requiredLabel5.setForeground(new java.awt.Color(255, 0, 0));
        requiredLabel5.setText("*");
		comintentActionButton = new javax.swing.JButton();
		comintentActionButton.setText(messageService.getMessage("comintent.adding"));
		comintentActionButton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				//Client presses save changes
				String errorMessage="";
				if (comintentActionButton.getText().equals(messageService.getMessage("organiazation.sector.action.save"))){
					Komintent komintent=new Komintent();
					try {
						komintent = assembleKomintentObject();
						komintent.setId(selectedComintent.getId());
						errorMessage=checRequiredFields(komintent);
						if (!errorMessage.equals("")){
							JOptionPane.showMessageDialog(component, errorMessage,"Error", JOptionPane.ERROR_MESSAGE);
						}
						else {
							modelService.update(komintent);
							
							clearComintentData();
							refreshTableData();
						}
					}
					catch (Exception e){
						System.out.println("Exception writing to database"+e.getClass());
						JOptionPane.showMessageDialog(component, messageService.getMessage("comintent.error.update.writing"),"Error", JOptionPane.ERROR_MESSAGE);
						modelService.refresh(komintent);
						clearComintentData();
						refreshTableData();
					}
				}
				//Client adds new comintent
				if (comintentActionButton.getText().equals(messageService.getMessage("organization.sector.action.add"))){
					try {
						Komintent komintent=assembleKomintentObject();
						errorMessage=checRequiredFields(komintent);
						if (!errorMessage.equals("")){
							JOptionPane.showMessageDialog(component, errorMessage,"Error", JOptionPane.ERROR_MESSAGE);
						}
						else {
							modelService.save(komintent);
							clearComintentData();
							refreshTableData();
						}
					}
					catch (Exception e){
						System.out.println("Exception writing to database"+e.getClass());
						JOptionPane.showMessageDialog(component, messageService.getMessage("comintent.error.writing"),"Error", JOptionPane.ERROR_MESSAGE);
					}
				}
				comintentPanel.setVisible(false);
			}
			
		});
	}
	
	
	@SuppressWarnings("all")
	private void initComintentTablePanel(){
		comintentTablePanel = new javax.swing.JPanel();
        comintentTablePanel.setBorder(BorderFactory.createTitledBorder(messageService.getMessage("comintent.edit")));
        comintentTableScrollPane = new javax.swing.JScrollPane();
        comintentTable = new javax.swing.JTable();
        comintentTable.setAutoCreateRowSorter(true);
        comintentTableModel= new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
            	"ID",messageService.getMessage("comintent.code"),messageService.getMessage("comintent.name"),
                messageService.getMessage("comintent.address"),messageService.getMessage("comintent.telephone"),
                messageService.getMessage("comintent.fax"),messageService.getMessage("comintent.emb"),
                messageService.getMessage("comintent.unique.tax.number"),messageService.getMessage("comintent.place")
            }
        ) {
            Class[] types = new Class [] {
            		java.lang.String.class,java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false,false, false, false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        };
        comintentTable.setModel(comintentTableModel);
        comintentTable.setAutoCreateRowSorter(true);    
        comintentTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        comintentTable.removeColumn(comintentTable.getColumn("ID"));
        comintentTableScrollPane.setViewportView(comintentTable);
	}
	
	//Fill all the fields with the selected Row in the comintentTable
//	private void fillSelectedComintentData(){
//		if (selectedComintent!=null){
//			comintentNameField.setText(selectedComintent.getName());
//			comintentShortNameField.setText(selectedComintent.getShortName());
//			uniqueTaxNumberField.setText(selectedComintent.getUniqueTaxNumber());
//			placeField.setText(selectedComintent.getPlace());
//			addressField.setText(selectedComintent.getAddress());
//			codeField.setText(selectedComintent.getCode());
//			telephoneField.setText(selectedComintent.getTelephone());
//			faxField.setText(selectedComintent.getFax());
//			EMBField.setText(selectedComintent.getEMBG());
//			accountBankNameField.setText(selectedComintent.getBankName());
//			accountBankNumberField.setText(selectedComintent.getAccoutNumber());
//			comintentActionButton.setText(messageService.getMessage("comintent.save.changes"));
//		}
//	}
	

	
	private javax.swing.JPanel actionPanel;
    private javax.swing.JButton addKomintent;
    private javax.swing.JButton modifyKomintent;
	private void initActionPanel(){
		 actionPanel=new JPanel();
		 actionPanel.setBorder(BorderFactory.createTitledBorder(messageService.getMessage("warrant.inputed.entries")));
	     addKomintent=new JButton();
	     addKomintent.setText(messageService.getMessage("comintent.action.new"));
	     addKomintent.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				comintentPanel.setVisible(true);
				comintentActionButton.setText(messageService.getMessage("organization.sector.action.add"));
				clearComintentData();
			}
		});
	   
	     modifyKomintent=new JButton();
	     modifyKomintent.setText(messageService.getMessage("comintent.action.modify"));
		 
	     modifyKomintent.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				if (comintentTable.getSelectedRow()>=0){
					int rowIndex=comintentTable.convertRowIndexToModel(comintentTable.getSelectedRow());
					selectedComintent=comintentList.get(rowIndex);
					comintentActionButton.setText(messageService.getMessage("organiazation.sector.action.save"));
					comintentNameField.setText(selectedComintent.getName());
					comintentShortNameField.setText(selectedComintent.getShortName());
					uniqueTaxNumberField.setText(selectedComintent.getUniqueTaxNumber());
					placeField.setText(selectedComintent.getPlace());
					addressField.setText(selectedComintent.getAddress());
					codeField.setText(selectedComintent.getCode());
					telephoneField.setText(selectedComintent.getTelephone());
					faxField.setText(selectedComintent.getFax());
					EMBField.setText(selectedComintent.getEMBG());
					accountBankNameField.setText(selectedComintent.getBankName());
					accountBankNumberField.setText(selectedComintent.getAccoutNumber());
					comintentPanel.setVisible(true);
				}
			}
		});
	}
	
		
	//Assemble Komintent Object from all the fields
	private Komintent assembleKomintentObject(){
		Komintent komintent=new Komintent();
		komintent.setName(comintentNameField.getText());
		komintent.setShortName(comintentShortNameField.getText());
		komintent.setUniqueTaxNumber(uniqueTaxNumberField.getText());
		komintent.setPlace(placeField.getText());
		komintent.setAddress(addressField.getText());
		komintent.setCode(codeField.getText());
		komintent.setTelephone(telephoneField.getText());
		komintent.setFax(faxField.getText());
		komintent.setEMBG(EMBField.getText());
		komintent.setBankName(accountBankNameField.getText());
		komintent.setAccoutNumber(accountBankNumberField.getText());
		return komintent;
	}
	
	//Clear all the fields
	private void clearComintentData(){
		comintentNameField.setText("");
		comintentShortNameField.setText("");
		uniqueTaxNumberField.setText("");
		placeField.setText("");
		addressField.setText("");
		codeField.setText("");
		telephoneField.setText("");
		faxField.setText("");
		EMBField.setText("");
		accountBankNameField.setText("");
		accountBankNumberField.setText("");
	}
	
	@SuppressWarnings("all")
	private void refreshTableData() {
		comintentList = modelService.findAll(Komintent.class);
		comintentTableModel.getDataVector().removeAllElements();
		comintentTable.setAutoCreateRowSorter(true);
		for (Komintent komintent : comintentList) {
			Vector row = new Vector();
			row.add(komintent.getId());
			row.add(komintent.getCode());
			row.add(komintent.getName());
			row.add(komintent.getAddress());
			row.add(komintent.getTelephone());
			row.add(komintent.getFax());
			row.add(komintent.getEMBG());
			row.add(komintent.getUniqueTaxNumber());
			row.add(komintent.getPlace());
			comintentTableModel.addRow(row);
		}
	}
	
	//check if all required fields has been filled
	public String checRequiredFields(Komintent komintent){
		if (komintent.getName().equals(""))
			return messageService.getMessage("comintent.no.name.inputed");
		if (komintent.getShortName().equals(""))
			return messageService.getMessage("comintent.no.short.name.inputed");
		if (komintent.getUniqueTaxNumber().equals(""))
			return messageService.getMessage("comintent.no.utn.inputed");
		if (komintent.getPlace().equals(""))
			return messageService.getMessage("comintent.no.place.inputed");
//		if (komintent.getEMBG().equals(""))
//			return messageService.getMessage("comintent.no.embg.inputed");
		if (komintent.getCode().equals(""))
			return messageService.getMessage("comintent.no.code.inputed");
		return "";
	}
	
	
	
	private void setLayout(){
		javax.swing.GroupLayout comintentPanelLayout = new javax.swing.GroupLayout(comintentPanel);
        comintentPanel.setLayout(comintentPanelLayout);
        comintentPanelLayout.setHorizontalGroup(
            comintentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(comintentPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(comintentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(uniqueTaxNumberLabel)
                    .addComponent(comintentShorNameLabel)
                    .addComponent(comintentNameLabel)
                    .addComponent(placeLabel)
                    .addComponent(addressLabel)
                    .addComponent(codeLabel))
                .addGap(18, 18, 18)
                .addGroup(comintentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(addressField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(comintentPanelLayout.createSequentialGroup()
                        .addComponent(comintentShortNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(requiredLabel1))
                    .addGroup(comintentPanelLayout.createSequentialGroup()
                        .addComponent(uniqueTaxNumberField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(requiredLabel2))
                    .addGroup(comintentPanelLayout.createSequentialGroup()
                        .addComponent(placeField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(requiredLabel3))
                    .addGroup(comintentPanelLayout.createSequentialGroup()
                        .addComponent(comintentNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(requiredLabel))
                    .addGroup(comintentPanelLayout.createSequentialGroup()
                        .addComponent(codeField, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(requiredLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 36, Short.MAX_VALUE)
                .addGroup(comintentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(telephoneLabel, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(faxLabel, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(EMBLabel, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(accountBankNameLabel, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(accountBankNumberName, javax.swing.GroupLayout.Alignment.TRAILING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(comintentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(accountBankNumberField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(telephoneField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(comintentActionButton)
                    .addGroup(comintentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, comintentPanelLayout.createSequentialGroup()
                            .addGroup(comintentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(faxField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(EMBField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(requiredLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addComponent(accountBankNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(22, 22, 22))
        );
        comintentPanelLayout.setVerticalGroup(
            comintentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(comintentPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(comintentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(comintentNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(comintentNameLabel)
                    .addComponent(requiredLabel)
                    .addComponent(telephoneLabel)
                    .addComponent(telephoneField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(comintentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(comintentShortNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(comintentShorNameLabel)
                    .addComponent(requiredLabel1)
                    .addComponent(faxLabel)
                    .addComponent(faxField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(comintentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(uniqueTaxNumberField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(uniqueTaxNumberLabel)
                    .addComponent(requiredLabel2)
                    .addComponent(EMBLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(EMBField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(requiredLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(comintentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(placeField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(placeLabel)
                    .addComponent(requiredLabel3)
                    .addComponent(accountBankNameLabel)
                    .addComponent(accountBankNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(comintentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(addressField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(addressLabel)
                    .addComponent(accountBankNumberName)
                    .addComponent(accountBankNumberField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(comintentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(codeField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(codeLabel)
                    .addComponent(comintentActionButton)
                    .addComponent(requiredLabel5))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        javax.swing.GroupLayout comintentTablePanelLayout = new javax.swing.GroupLayout(comintentTablePanel);
        comintentTablePanel.setLayout(comintentTablePanelLayout);
        comintentTablePanelLayout.setHorizontalGroup(
            comintentTablePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(comintentTablePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(comintentTableScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 846, Short.MAX_VALUE)
                .addContainerGap())
        );
        comintentTablePanelLayout.setVerticalGroup(
            comintentTablePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, comintentTablePanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(comintentTableScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        javax.swing.GroupLayout actionPanelLayout = new javax.swing.GroupLayout(actionPanel);
        actionPanel.setLayout(actionPanelLayout);
        actionPanelLayout.setHorizontalGroup(
            actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(actionPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(addKomintent)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(modifyKomintent)
                .addContainerGap(62, Short.MAX_VALUE))
        );
        actionPanelLayout.setVerticalGroup(
            actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(actionPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(addKomintent)
                    .addComponent(modifyKomintent))
                .addContainerGap(12, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(comintentPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(comintentTablePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(actionPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(150, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(comintentPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(actionPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(comintentTablePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(303, Short.MAX_VALUE))
        );
	}
}